package com.example.controller;


import com.example.entity.Gouwuche;
import com.example.entity.GouwucheType;
import com.example.service.IGouwucheService;
import com.example.service.IGouwucheTypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
@RequestMapping("/gouwuche")

public class GouwucheController {
    @Autowired
    private IGouwucheService gouwucheService;

    @Autowired
    private IGouwucheTypeService goueucheTypeService;
    @GetMapping("/index")
    public String index(String name, Integer typeId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize, HttpServletRequest request){

        PageInfo<Gouwuche> pageInfo = gouwucheService.findAll(name,typeId,pageNum,pageSize);

        request.setAttribute("pageInfo",pageInfo);

        //产品类型
        List<GouwucheType> typeList = goueucheTypeService.findAll();

        request.setAttribute("typeList",typeList);

        //数据的回显
        request.setAttribute("typeId",typeId);

        request.setAttribute("name",name);

        return "gouwuche/gouwuche";
    }
}
